package cn.bob.feign;

import cn.bob.dto.BuyNumDto;
import cn.bob.dto.SelectByMovieDto;
import cn.bob.result.JsonResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import javax.validation.Valid;

@Component
public class SentinelClientFallbackFactory implements FallbackFactory<MovieServer> {
    @Override
    public MovieServer create(Throwable throwable) {
        return new MovieServer() {
            @Override
            public JsonResult list() {
                return JsonResult.error("查询所有的服务被熔断了!!");
            }

            @Override
            public JsonResult buy(@Valid BuyNumDto buyNumDto) {
                return JsonResult.error("购买电影票的接口被熔断了");
            }

            @Override
            public JsonResult selectByMovie(@Valid SelectByMovieDto selectByMovieDto) {
                return JsonResult.error("查询电影票是否过期被熔断了");
            }

            @Override
            public JsonResult get(Long id) {
                return JsonResult.error("查询单条电影是否过期被熔断了");
            }

            @Override
            public JsonResult randomMovie(Long userId) {
                return JsonResult.error("赠送电影票被熔断了");
            }

            @Override
            public JsonResult seeMovie(@Valid BuyNumDto buyNumDto) {
                return JsonResult.error("看电影接口被熔断了");
            }

        };
    }
}
